<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Install extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        // 会员表
        $members = $this->table('members', ['id' => 'member_id']);
        $members->addColumn('uuid', 'uuid', ['limit' => 100, 'comment' => '会员UUID'])
            ->addColumn('nickname', 'string', ['limit' => 50, 'comment' => '会员昵称'])
            ->addColumn('email', 'string', ['limit' => 100, 'comment' => '会员邮箱'])
            ->addColumn('password', 'string', ['limit' => 60, 'comment' => '会员密码HASH'])
            ->addColumn('avatar', 'string', ['limit' => 200, 'comment' => '会员头像'])
            ->addColumn('motto', 'string', ['null' => true, 'limit' => 200, 'comment' => '会员座右铭'])
            ->addColumn('bio', 'string', ['null' => true, 'limit' => 255, 'comment' => '会员简介'])
            ->addColumn('create_ip', 'string', ['limit' => 32, 'comment' => '会员注册IP'])
            ->addColumn('create_time', 'integer', ['limit' => 10, 'comment' => '会员注册时间'])
            ->addColumn('last_login_ip', 'string', ['null' => true, 'limit' => 32, 'comment' => '会员上次登录IP'])
            ->addColumn('last_login_time', 'integer', ['null' => true, 'limit' => 10, 'comment' => '会员上次登录时间'])
            ->addColumn('update_ip', 'string', ['limit' => 32, 'comment' => '会员更新IP'])
            ->addColumn('update_time', 'integer', ['limit' => 10, 'comment' => '会员更新时间'])
            ->addColumn('delete_time', 'integer', ['null' => true, 'limit' => 10, 'comment' => '会员软删除时间'])
            ->addColumn('status', 'integer', ['limit' => 1, 'comment' => '会员状态'])
            ->create();

        // 会员角色表
        $roles = $this->table('roles', ['id' => 'role_id']);
        $roles->addColumn('name', 'string', ['limit' => 100, 'comment' => '角色名称'])
            ->addColumn('rules', 'text', ['comment' => '角色权限规则'])
            ->addColumn('is_system', 'integer', ['default' => 0, 'limit' => 1, 'comment' => '系统角色|拥有不可更改不可删除特性'])
            ->addColumn('create_ip', 'string', ['limit' => 32, 'comment' => '角色创建IP'])
            ->addColumn('create_time', 'integer', ['limit' => 10, 'comment' => '角色创建时间'])
            ->addColumn('update_ip', 'string', ['limit' => 32, 'comment' => '角色更新IP'])
            ->addColumn('update_time', 'integer', ['limit' => 10, 'comment' => '角色更新时间'])
            ->addColumn('delete_time', 'integer', ['null' => true, 'limit' => 10, 'comment' => '角色软删除时间'])
            ->addColumn('status', 'integer', ['limit' => 1, 'comment' => '角色状态'])
            ->create();

        // 会员互联信息表
        $connects = $this->table('connects', ['id' => 'connect_id']);
        $connects->addColumn('uuid', 'string', ['limit' => 100, 'comment' => '会员UUID'])
            ->addColumn('openid', 'string', ['null' => true, 'limit' => 100, 'comment' => '会员该互联唯一OPENID'])
            ->addColumn('type', 'integer', ['limit' => 1, 'comment' => '互联类型|QQ/WeChat/Weibo/Github'])
            ->addColumn('access_token', 'string', ['limit' => 100, 'comment' => '互联登录提供商返回的Token'])
            ->addColumn('expires_time', 'integer', ['limit' => 10, 'comment' => 'Access_token过期时间'])
            ->addColumn('create_ip', 'string', ['limit' => 32, 'comment' => '角色创建IP'])
            ->addColumn('create_time', 'integer', ['limit' => 10, 'comment' => '角色创建时间'])
            ->addColumn('update_ip', 'string', ['limit' => 32, 'comment' => '角色更新IP'])
            ->addColumn('update_time', 'integer', ['limit' => 10, 'comment' => '角色更新时间'])
            ->create();

        // 系统配置表
        $options = $this->table('options', ['id' => 'option_id']);
        $options->addColumn('name', 'string', ['limit' => 255, 'comment' => '配置名称'])
            ->addColumn('value', 'text', ['comment' => '配置内容'])
            ->addColumn('base', 'string', ['limit' => 100, 'comment' => '配置所属'])
            ->addColumn('type', 'integer', ['default' => 1, 'limit' => 1, 'comment' => '配置类型|1文本型 2整数型 3布尔型'])
            ->addColumn('create_ip', 'string', ['limit' => 32, 'comment' => '配置创建IP'])
            ->addColumn('create_time', 'integer', ['limit' => 10, 'comment' => '配置创建时间'])
            ->addColumn('update_ip', 'string', ['limit' => 32, 'comment' => '配置更新IP'])
            ->addColumn('update_time', 'integer', ['limit' => 10, 'comment' => '配置更新时间'])
            ->addColumn('delete_time', 'integer', ['null' => true, 'limit' => 10, 'comment' => '配置软删除时间'])
            ->create();

        // 操作日志表
        $oplogs = $this->table('oplogs', ['id' => 'oplog_id']);
        $oplogs->addColumn('uuid', 'string', ['limit' => 100, 'comment' => '操作人UUID'])
            ->addColumn('action', 'text', ['comment' => '操作方法/路径/请求'])
            ->addColumn('value', 'text', ['comment' => '操作内容'])
            ->addColumn('create_ip', 'string', ['limit' => 32, 'comment' => '操作创建IP'])
            ->addColumn('create_time', 'integer', ['limit' => 10, 'comment' => '操作创建时间'])
            ->addColumn('update_ip', 'string', ['limit' => 32, 'comment' => '操作更新IP'])
            ->addColumn('update_time', 'integer', ['limit' => 10, 'comment' => '操作更新时间'])
            ->addColumn('delete_time', 'integer', ['null' => true, 'limit' => 10, 'comment' => '操作软删除时间'])
            ->create();

        // 帖子表
        $posts = $this->table('posts', ['id' => 'post_id']);
        $posts->addColumn('title', 'string', ['limit' => 255, 'comment' => '帖子标题'])
            ->addColumn('uuid', 'string', ['limit' => 100, 'comment' => '发布人UUID'])
            ->addColumn('content', 'text', ['comment' => '帖子内容'])
            ->addColumn('views', 'integer', ['limit' => 11, 'comment' => '帖子查看次数'])
            ->addColumn('comment_count', 'string', ['limit' => 200, 'comment' => '帖子评论数目'])
            ->addColumn('create_ip', 'string', ['limit' => 32, 'comment' => '帖子创建IP'])
            ->addColumn('create_time', 'integer', ['limit' => 10, 'comment' => '帖子创建时间'])
            ->addColumn('update_ip', 'string', ['limit' => 32, 'comment' => '帖子更新IP'])
            ->addColumn('update_time', 'integer', ['limit' => 10, 'comment' => '帖子更新时间'])
            ->addColumn('delete_time', 'integer', ['null' => true, 'limit' => 10, 'comment' => '帖子软删除时间'])
            ->addColumn('status', 'integer', ['limit' => 1, 'comment' => '帖子状态'])
            ->create();

        // 评论表
        $comments = $this->table('comments', ['id' => 'comment_id']);
        $comments->addColumn('post_id', 'integer', ['limit' => 11, 'comment' => '帖子ID'])
            ->addColumn('uuid', 'string', ['limit' => 100, 'comment' => '发布人UUID'])
            ->addColumn('reply_id', 'integer', ['limit' => 11, 'comment' => '回复评论ID'])
            ->addColumn('content', 'text', ['comment' => '评论内容'])
            ->addColumn('like_count', 'integer', ['limit' => 11, 'comment' => '评论点赞次数'])
            ->addColumn('tread_count', 'integer', ['limit' => 11, 'comment' => '评论踩次数'])
            ->addColumn('create_ip', 'string', ['limit' => 32, 'comment' => '评论创建IP'])
            ->addColumn('create_time', 'integer', ['limit' => 10, 'comment' => '评论创建时间'])
            ->addColumn('update_ip', 'string', ['limit' => 32, 'comment' => '评论更新IP'])
            ->addColumn('update_time', 'integer', ['limit' => 10, 'comment' => '评论更新时间'])
            ->addColumn('delete_time', 'integer', ['null' => true, 'limit' => 10, 'comment' => '评论软删除时间'])
            ->addColumn('status', 'integer', ['limit' => 1, 'comment' => '评论状态'])
            ->create();
    }
}
